home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / BORLAND TURBO / DYNAB.PAK / ADDFIELD.CPP next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.4 KB  |  100 lines

  1. // addfield.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13.  
  14. #include "stdafx.h"
  15. #include "enroll.h"
  16. #include "sectset.h"
  17. #include "addfield.h"
  18. #include "columnst.h"
  19.  
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CAddField dialog
  27.  
  28. CAddField::CAddField(CWnd* pParent /*=NULL*/)
  29.     : CDialog(CAddField::IDD, pParent)
  30. {
  31.     //{{AFX_DATA_INIT(CAddField)
  32.     m_strField = "";
  33.     //}}AFX_DATA_INIT
  34. }
  35.  
  36. void CAddField::DoDataExchange(CDataExchange* pDX)
  37. {
  38.     CDialog::DoDataExchange(pDX);
  39.     //{{AFX_DATA_MAP(CAddField)
  40.     DDX_Control(pDX, IDC_LIST1, m_lbFields);
  41.     DDX_LBString(pDX, IDC_LIST1, m_strField);
  42.     //}}AFX_DATA_MAP
  43. }
  44.  
  45. BEGIN_MESSAGE_MAP(CAddField, CDialog)
  46.     //{{AFX_MSG_MAP(CAddField)
  47.     //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49.  
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CAddField message handlers
  53.  
  54. BOOL CAddField::OnInitDialog()
  55. {
  56.     CDialog::OnInitDialog();
  57.  
  58.     CColumns* pcols = new CColumns(m_pSet->m_pDatabase);
  59.     pcols->OnSetOptions(pcols->m_hstmt);
  60.  
  61.     RETCODE nRetCode;
  62.     AFX_SQL_ASYNC(pcols, ::SQLColumns(pcols->m_hstmt,
  63.         (UCHAR *)NULL, SQL_NTS, (UCHAR *)NULL, SQL_NTS,
  64.         (UCHAR *)(const char *)m_pSet->GetTableName(), SQL_NTS,
  65.         (UCHAR *)NULL, SQL_NTS));
  66.     if (!pcols->Check(nRetCode))
  67.     {
  68.         AfxMessageBox("SQLColumns failed\n", MB_OK | MB_ICONEXCLAMATION);
  69.         return TRUE;
  70.     }
  71.  
  72.     // Position on first record
  73.     pcols->MoveNext();
  74.  
  75.     UINT ccols = 0;
  76.     while (!pcols->IsEOF())
  77.     {
  78.         CFieldInfo Info;
  79.  
  80.         if ((pcols->m_nDataType == SQL_CHAR || pcols->m_nDataType == SQL_VARCHAR) &&
  81.             !m_pSet->FindField(pcols->m_strColumnName))
  82.         {
  83.             ccols++;
  84.             m_lbFields.AddString(pcols->m_strColumnName);
  85.         }
  86.         pcols->MoveNext();
  87.     }
  88.  
  89.     m_lbFields.SetSel(0);
  90.  
  91.     if (ccols == 0)
  92.         AfxMessageBox("No additional columns available to add.\n", MB_OK | MB_ICONEXCLAMATION);
  93.  
  94.     delete pcols;
  95.  
  96.     m_lbFields.SetCurSel(0);
  97.  
  98.     return TRUE;  // return TRUE  unless you set the focus to a control
  99. }
  100.